from django.contrib import admin
from django.utils.translation import ugettext_lazy as _
from .models import Cover
from django.contrib.contenttypes.models import ContentType


@admin.register(Cover)
class CoverAdmin(admin.ModelAdmin):
    list_display = ('caption', 'cover', 'cover_thumbnail',)
    actions = ['make_published']

    def make_published(self, request, queryset):
        for qs in queryset:
            print(qs)
        selected = request.POST.getlist(admin.ACTION_CHECKBOX_NAME)
        ct = ContentType.objects.get_for_model(queryset.model)
        # 此处假设使用更新
        rows_updated = queryset.update(caption='Pub' * 2)
        if rows_updated == 1:
            message_bit = _("1 story was")
        else:
            message_bit = _("%s stories were") % rows_updated
        # 提示用户成功操作的数量
        self.message_user(request, _("%s successfully marked as published.") % message_bit)
